package algorithm.poj.p1000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;

/**
 * 分析：
 * 实现：
 * 经验：
 * 教训：
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P1565 {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P1565.class.getResource("P1565.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		String line = stdin.readLine();
		while (line != null && !"0".equals(line)) {
			System.out.println(skew(line.toCharArray()));
			line = stdin.readLine();
		}
	}

	private static long skew(char[] cs) {
		long v = 0;
		for (int i = 0; i < cs.length; i ++) {
			v += ((1<<(cs.length-i)) - 1)*(cs[i]-'0'); 
		}
		return v;
	}
}